import 'dart:convert';

/// dic_mo.dart
/// Create by Ethanz
/// Date: 2021-08-26
///
/// Description:
///

List<DicItemMo> dicListFormMap(List<dynamic> jsonList) {
  return jsonList.map((e) => DicItemMo.fromMap(e)).toList();
}

class DicItemMo {
  DicItemMo({
    this.dictId,
    this.dictType,
    this.dictTypeName,
    this.dictCode,
    this.dictName,
    this.hasChild,
    this.parentId,
    this.sort,
    this.state,
    this.childList,
  });

  int? dictId;
  String? dictType;
  String? dictTypeName;
  String? dictCode;
  String? dictName;
  int? hasChild;
  int? parentId;
  int? sort;
  int? state;
  List<DicItemMo>? childList;

  factory DicItemMo.fromJson(String str) => DicItemMo.fromMap(json.decode(str));

  String toJson() => json.encode(toMap());

  factory DicItemMo.fromMap(Map<String, dynamic> json) => DicItemMo(
        dictId: json["dictId"],
        dictType: json["dictType"],
        dictTypeName: json["dictTypeName"],
        dictCode: json["dictCode"],
        dictName: json["dictName"],
        hasChild: json["hasChild"],
        parentId: json["parentId"],
        sort: json["sort"],
        state: json["state"],
        childList: json["childList"] == null
            ? null
            : List<DicItemMo>.from(
                json["childList"].map((x) => DicItemMo.fromMap(x))),
      );

  Map<String, dynamic> toMap() => {
        "dictId": dictId,
        "dictType": dictType,
        "dictTypeName": dictTypeName,
        "dictCode": dictCode,
        "dictName": dictName,
        "hasChild": hasChild,
        "parentId": parentId,
        "sort": sort,
        "state": state,
        "childList": List<dynamic>.from(childList?.map((x) => x.toMap()) ?? []),
      };
}
